package com.yykj.hospital.server.model.entity;

import com.yykj.common.constant.CommonConstant;
import com.yykj.common.enums.HospitalOnlineTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;


@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class HospitalSettingOnline {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ApiModelProperty("ID")
    private Integer id;
    @ApiModelProperty("医院ID")
    private Integer hospitalId;
    @Enumerated(value = EnumType.STRING)
    @ApiModelProperty("在线问诊类型")
    private HospitalOnlineTypeEnum type;
    @ApiModelProperty("名称")
    private String name;
    @ApiModelProperty("服务时长")
    private Integer time;
    @ApiModelProperty("说明")
    private String detail;
    @ApiModelProperty("启用停用状态")
    private Boolean status;

    @ApiModelProperty("价格")
    @Column(precision = 10,scale = 2)
    private BigDecimal price;


    @CreationTimestamp
    private LocalDateTime addTime;
    @UpdateTimestamp
    private LocalDateTime modifyTime;

    public static HospitalSettingOnline defaultHospitalSettingOnline(Integer hospitalId, HospitalOnlineTypeEnum type) {
        HospitalSettingOnline online = HospitalSettingOnline.builder()
                .hospitalId(hospitalId)
                .type(type)
                .time(15)
                .status(Boolean.TRUE)
                .build();

        switch (type) {
            case xufang:
                online.setName(CommonConstant.XU_FANG);
                online.setDetail(CommonConstant.XU_FANG + "说明");
                online.setPrice(CommonConstant.DEFAULT_PRICE);
                online.setTime(30);
                break;
            case pic:
                online.setName(CommonConstant.PIC);
                online.setDetail(CommonConstant.PIC + "说明");
                online.setPrice(CommonConstant.PIC_PRICE);
                online.setTime(30);
                break;
            case voice:
                online.setName(CommonConstant.VOICE);
                online.setDetail(CommonConstant.VOICE + "说明");
                online.setPrice(CommonConstant.VOICE_PRICE);
                break;
            case video:
                online.setName(CommonConstant.VIDEO);
                online.setDetail(CommonConstant.VIDEO + "说明");
                online.setPrice(CommonConstant.VIDEO_PRICE);
                break;
            default:
                break;
        }
        return online;
    }

    public static List<HospitalSettingOnline> defaultHospitalSettingOnline(Integer hospitalId) {
        List<HospitalSettingOnline> result = new ArrayList<>();
        HospitalSettingOnline setting = HospitalSettingOnline.builder()
                .hospitalId(hospitalId)
                .type(HospitalOnlineTypeEnum.video)
                .name(CommonConstant.VIDEO)
                .detail(CommonConstant.VIDEO + "说明")
                .time(15)
                .price(CommonConstant.VIDEO_PRICE)
                .status(Boolean.TRUE)
                .build();
        result.add(setting);

        setting = HospitalSettingOnline.builder()
                .hospitalId(hospitalId)
                .type(HospitalOnlineTypeEnum.voice)
                .name(CommonConstant.VOICE)
                .detail(CommonConstant.VOICE + "说明")
                .time(15)
                .price(CommonConstant.VOICE_PRICE)
                .status(Boolean.TRUE)
                .build();
        result.add(setting);
        setting = HospitalSettingOnline.builder()
                .hospitalId(hospitalId)
                .type(HospitalOnlineTypeEnum.pic)
                .name(CommonConstant.PIC)
                .detail(CommonConstant.PIC + "说明")
                .time(30)
                .price(CommonConstant.PIC_PRICE)
                .status(Boolean.TRUE)
                .build();
        result.add(setting);

        setting = HospitalSettingOnline.builder()
                .hospitalId(hospitalId)
                .type(HospitalOnlineTypeEnum.xufang)
                .name(CommonConstant.XU_FANG)
                .detail(CommonConstant.XU_FANG + "说明")
                .time(30)
                .price(CommonConstant.DEFAULT_PRICE)
                .status(Boolean.TRUE)
                .build();
        result.add(setting);

        return result;
    }
}
